package scu.maqiang.eigenvalue;

import java.util.Arrays;

import scu.maqiang.fes.BVPType;
import scu.maqiang.fes.FES1L21;
import scu.maqiang.mesh.Mesh1L2;
import scu.maqiang.numeric.Direct;
import scu.maqiang.numeric.EigenSSolver;
import scu.maqiang.numeric.MVO;
import scu.maqiang.numeric.SRMatrix;

public class ConvectDiffuseEigenValue1DL21 {

	public static void main(String[] args) {
		Mesh1L2 mesh = new Mesh1L2();
		mesh.line(0, 1.0, 2048);
		mesh.scale(Math.PI);
		
		FES1L21 fs = new FES1L21(mesh);
		SRMatrix A = new SRMatrix(fs.GetNdof());
		SRMatrix M = new SRMatrix(fs.GetNdof());
		
		int N = 10;
		double[] D = new double[N];
		double[][] V = new double[N][fs.GetNdof()];
		double[] x = new double[fs.GetNdof()];
		Arrays.fill(x, 1.0);
		fs.assembleStiff(new double[]{10.0}, BVPType.COMMON, A);
		fs.assembleConvection(new double[] {1.0}, BVPType.COMMON, A);
//		A.sort();
//		System.out.println(A);
		fs.assembleMass(new double[]{1.0}, BVPType.CONSIST_MASS, M);
		//M.sort();
		//System.out.println(M);
		fs.applyBC_MBN(A, x, Direct.All, 0.0, 1, 2);
		//fs.applyBCZero(A, x, Direct.X, BCType.RCE, 1, 2);
		//System.out.println(A);
		EigenSSolver solver = new EigenSSolver();
		solver.inversePowerTran_PLU(A, M, fs.getnBand(), x, 40.0, N, D, V);
		//solver.inversePowerTran_GMRES(A, M, x, 20.0, N, D, V);
		//solver.inversePowerTran_PLU(A, M, fs.getnBand(), x, 2.0, N, D, V);
		System.out.println(MVO.toString(D));
		mesh.toTecplot("ConvectDiffusionEigenvalue1D.dat", V);
	}
}
